package com.jiangyg.mall.authz.support.authentication.admin;

import com.jiangyg.mall.admin.vo.UserAuthzInfoVO;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * 类描述：后台管理用户信息
 *
 * @author jiangyg
 * @version 4.0
 * @date 2022-01-05
 */
// TODO 考虑替换 UserInfo
public class AdminUserDetails implements UserDetails {

    private static final long serialVersionUID = -8675246504455108316L;

    /**
     * 用户ID
     */
    private String id;

    /**
     * 用户名
     */
    private String username;

    /**
     * 用户姓名
     */
    private String fullname;

    /**
     * 密码
     */
    private String password;

    /**
     * 邮箱
     */
    private String mail;

    /**
     * 电话
     */
    private String phone;

    /**
     * 权限列表（资源列表或者角色代码等等都可以，只要能辨别权限的标识）
     */
    private List<? extends GrantedAuthority> authorities;

    public AdminUserDetails() {
    }

    public AdminUserDetails(UserAuthzInfoVO info) {
        this.setId(info.getId());
        this.setUsername(info.getUsername());
        this.setPassword(info.getPassword());
        this.setFullname(info.getFullname());
        this.setMail(info.getMail());
        this.setPhone(info.getPhone());
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getFullname() {
        return fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    public void setAuthorities(List<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

}
